﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

/// <summary>
/// Summary description for UpdateInfo
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class UpdateInfo : System.Web.Services.WebService {
    security baomat = new security();
    public UpdateInfo () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }
    [WebMethod]
    public bool UpdateBasicInfo(string username,string Fullname,DateTime Birthday)
    {
        bool result = false;
        try
        {
            using (Up1VNDataContext dc = new Up1VNDataContext())
            {
                if (Fullname != "" || Birthday.ToShortDateString() != "")
                {
                    User U = dc.Users.Single(c => c.Users_Name == username);
                    if (Fullname != "")
                        U.Users_FullName = Fullname.Trim();
                    if (Birthday.ToShortDateString() != "")
                        U.Users_BirdthDay = Convert.ToDateTime(baomat.convertTimeTo_Mdy(Birthday.ToShortDateString()));
                    dc.SubmitChanges();
                    result = true;
                }
                else
                    result = false;
            }
        }
        catch (Exception ex)
        {
            result = false;
        }
        return result;
    }
    [WebMethod]
    public bool UpdateContactInfo(string username,string address,string phoneNum,string yahoochat,string skypechat)
    {
        bool result = false;
        try
        {
            using (Up1VNDataContext dc = new Up1VNDataContext())
            {
                User U = dc.Users.Single(c => c.Users_Name == username);
                U.Users_Address = address;
                U.Users_MobilePhone = phoneNum;
                U.Users_YahooNick = yahoochat;
                U.Users_SkypeNick = skypechat;
                dc.SubmitChanges();
                result = true;
            }
        }
        catch (Exception ex)
        {
            result = false;
        }
        return result;
    }
    [WebMethod]
    public string HelloWorld() {
        return "Hello World";
    }
    
}
